package org.example;

import java.util.ArrayList;

public class PhoneTest {
    public static void main(String[] args) {
        ArrayList<Phone> list = new ArrayList<>();


        //创建对象
        Phone p1 = new Phone("小米", 2000);
        Phone p2 = new Phone("华为", 1000);
        Phone p3 = new Phone("苹果", 3000);

        list.add(p1);
        list.add(p2);
        list.add(p3);

        ArrayList<Phone> newList = getPhone(list);
        for (int i = 0; i < newList.size(); i++) {
            Phone p=newList.get(i);
            System.out.println(p.getBrand()+","+p.getPrice());
        }

    }

    public static ArrayList<Phone> getPhone(ArrayList<Phone> list) {
        ArrayList<Phone> newList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Phone p = list.get(i);
            if (p.getPrice() < 3000) {
                newList.add(p);
            }
        }
        return newList;
    }
}
